﻿using System;
using System.IO;
using System.Web;
using HiauPdm.Bll;

namespace HiauPdm.Web
{
    public partial class DownloadFile : PageBase
    {
        protected override bool IsAccess()
        {
            return true;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            try
            {
                string[] sFiles = BGlobal.Decrypt(Request.QueryString["id"], "Download").Split('|');
                if (File.Exists(string.Format("{0}{1}", BGlobal.AttachmentPath, sFiles[0])))
                {
                    sFiles[1] = Server.UrlEncode(sFiles[1]);
                    if (sFiles[1].LastIndexOf(".") > 0)
                    {
                        sFiles[1] = sFiles[1].Substring(0, sFiles[1].LastIndexOf(".")).Replace(".", "%2e") + sFiles[1].Substring(sFiles[1].LastIndexOf("."));
                    }
                    Response.ContentType = "application/octet-stream;charset=utf-8";
                    Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", sFiles[1]));
                    Response.WriteFile(string.Format("{0}{1}", BGlobal.AttachmentPath, sFiles[0]));
                }
            }
            catch { }
            Response.End();
        }
    }
}
